Main site

Built-in Modules > Shein Class

Shein Class

Important: This plugin relies on third-party resources. The resources might change or be discontinued without notice. Ensure you test the plugin extensively before production use, implement error handling with a try-catch block, have a backup shipping rate ready, and reach out to our support with detailed descriptions of any unexpected issues.

Overview

The Shein class is a tool for obtaining real-time shipping rates for Shein products.

Class Definition

class Shein {
  constructor(destination, currency) {
    // Class constructor
  }

  async getRates(sheinProducts) {
    // Method to fetch rates
  }
}

Arguments

  • destination (Object): This parameter corresponds to the "destination" field from the DATA JSON object required by the calculateShippingRates function.
  • currency (String): The currency ISO code to be used for the shipping rates.

Usage Example

import { Shein } from "./modules.js"
const shein = new Shein(DATA.destination, DATA.currency);
const sheinProducts = [
  { shien_product_cost: 10, quantity: 1 },
  { shien_product_cost: 5, quantity: 1 },
  // ... more products
];
const rates = await shein.getRates(sheinProducts);

In this example, sheinProducts is an array of objects, with each object representing a Shein product through its cost in USD (shien_product_cost) and the quantity desired. The getRates method is called to retrieve shipping rates, which will be formatted in accordance with Shopify's rates structure.

Note that the shien_product_cost is the item's Shein price in USD, not your selling price. The rates are calculated based on the information on: Shein website

Sample AI Prompt

I'd like a shipping rate calculator for items from Shein products.
Enrich the data with metafield namespace "market" with size 10.
The Shein product cost for each items is saved in the data items metafield "market" with key named "shein_product_cost".

Sample AI Output

import { enrichItemDetails } from "./modules.js";
import { Shein } from "./modules.js";

export async function calculateShippingRates(DATA, env) {
  try {
    // Enrich data with metafield namespace "market" with size 10
    DATA = await enrichItemDetails(DATA, [{ namespace: "market", size: 10 }]);

    // Get Shein product cost for each item
    const sheinProducts = DATA.items.map((item) => {
      const sheinProductCost =
        item.metafields?.market?.find(
          (metafield) => metafield.key === "shein_product_cost"
        )?.value ?? 0;
      return {
        shein_product_cost: sheinProductCost,
        quantity: item.quantity,
      };
    });

    // Create a new Shein instance with destination and currency
    const shein = new Shein(DATA.destination, DATA.currency);

    // Get shipping rates from Shein
    const rates = await shein.getRates(sheinProducts);

    // Return shipping rates in Shopify format
    return { rates };
  } catch (error) {
    // Return error rate
    return {
      rates: [
        {
          service_name: "",
          service_code: "",
          total_price: null,
          description: "",
          currency: "",
          min_delivery_date: "",
          max_delivery_date: "",
        },
      ],
    };
  }
}